/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Engine2D.camera;


import Engine2D.entity.Entity;
import Engine2D.entity.Player;
import Engine2D.input.InputHandler;
import Engine2D.level.Level;
import org.lwjgl.input.Keyboard;

/**
 *
 * @author Garys
 */
public class FollowCamera extends Camera {

    private Entity entity;
    private InputHandler input = null;
    private boolean follow = true;

    /**
     * 
     * @param entity
     * @param input
     * @param level
     */
    public FollowCamera(Entity entity, InputHandler input, Level level) {
        this.entity = entity;
        this.input = input;
        this.level = level;
        followEntity();
    }

    /**
     * 
     */
    public void tick() {
        super.tick();
        if (follow) {
            ((Player)entity).start();
            followEntity();
        } else {

            if (input.isKeyDown(Keyboard.KEY_UP)) {
                y -= 12;
            }
            if (input.isKeyDown(Keyboard.KEY_DOWN)) {
                y += 12;
            }
            if (input.isKeyDown(Keyboard.KEY_LEFT)) {
                x -= 12;
            }
            if (input.isKeyDown(Keyboard.KEY_RIGHT)) {
                x += 12;
            }
        }

        if (input.isKeyPressed(Keyboard.KEY_F)) {
            follow = !follow;
            ((Player)entity).stop();
        }
    }

    private void followEntity() {
        this.x = entity.x;
        this.y = entity.y;
    }
}
